<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<jsp:include flush="true" page="../getCookie.jsp"></jsp:include>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
     <script type="text/javascript">
     
        $(function(){
           initCompanyShow();
        });
        function saveCompany(){
           var companyName = $("#companyName").val();
           var companyPrefix = $("#companyPrefix").val();
           
           if(companyName == ''){
              alert("公司名称不能为空");
              return;
           }
           
           if(companyPrefix == ''){
              alert("公司前缀不能为空");
              return;
           }
           
           var param = $("#companyForm").serialize();
           $.post("cts/saveCompany.action" , param , function(data){
              if(data == 1){
                var companyid = '<s:property value="company.id"/>';
                if(companyid!=''){
                  alert("公司更新成功");
                  window.location.href = "${pageContext.request.contextPath}/cts/index";
                }else{
                  alert("公司注册成功");
                  window.location.href = "${pageContext.request.contextPath}/cts/index";
                }
                
                window.location.reload();
              }else if(data == 2){
                 alert("公司前缀已存在");
              }else if(data == 3){
                 alert("公司名字已存在");
              }
           });
        }
        
          // 个人近照
        function showUpLoadPage(obj){
		     if(!(document.cookie || navigator.cookieEnabled)){
		        alert("请开启cookie");
		        return;
		     }
		     
		     var randomnumber = Math.floor(Math.random() * 100000);
		     $("#uploadImage").find("iframe[id='headIframeI']").remove();
		     $("#uploadImage").find("div[class='popdiv_content']").html('<iframe id="headIframeI" src="javascript:void(0)" style="width:317px;height:420px;margin:0px;padding:0px;" frameborder="0" scrolling="no"></iframe>'); 
			 $("#uploadImage").find("iframe[id='headIframeI']").attr("src" , "toImageTool?uptype=2&ishead=true&randomnumber="+randomnumber);  
		     $("#uploadImage").find("div[class='popdiv_handle']").text("公司LOGO");
		     openPopDiv( 'uploadImage' , '' ,  200); 
	   }
	   
	   function imgReturnVal(isTimeFile , fileBookName , imgUrl , imgName){
	      var randomnumber = Math.floor(Math.random() * 100000);
	      imgUrl = '${pageContext.request.contextPath}/' + imgUrl+"?time="+randomnumber
	      $("#imgHeadCpy").attr("src" , imgUrl);
	      $("#cpyLogth").val(imgName);
	      $("#isTimeUp").val(isTimeFile);
	      $("#timeFileName").val(fileBookName);
	      
	      $("#uploadImage").hide();
	   }
	   
	   function initCompanyShow(){
	      var companyStatus = '<s:property value="company.status"/>';
	      if(companyStatus == 2){
	          $("#showCompanyInfo").show();
		      $("#inputTools").hide();
	      }
	   }
	   
     </script>
  </head>
  
  <body>
	    <form action="saveCompany" id="companyForm" name="n_companyForm">  
		     <input type="hidden" id="companyid" name="companyid" value="<s:property value="company.id"/>"/>
	         
 		     <table border="0">
 		       <tr>
 		          <td rowspan="6" valign="top" title="上传头像">
	 		            <s:if test="company==null || #cts_emplcpyid == #cts_companyid">
	 		                <s:if test="company == null || company.logoPath == '' || company.logoPath==null">
				               <img id="imgHeadCpy" src="${pageContext.request.contextPath}/cts/images/original.jpg" style="width:40px;height:40px;margin-top:4px;cursor:pointer;">
				            </s:if>
				            <s:else>
				               <img id="imgHeadCpy"  src="${pageContext.request.contextPath}/upload/company/<s:property value="company.id"/>/<s:property value="company.logoPath"/>"  style="width:40px;height:40px;margin-top:4px;cursor:pointer;"/>
				            </s:else>
	 		            </s:if>
	 		            <s:else>
				             <s:if test="company == null || company.logoPath == '' || company.logoPath==null">
				               <img id="imgHeadCpy" src="${pageContext.request.contextPath}/cts/images/original.jpg" style="width:40px;height:40px;margin-top:4px;cursor:default;"/>
				             </s:if>
				             <s:else>
				               <img id="imgHeadCpy"  src="${pageContext.request.contextPath}/upload/company/<s:property value="company.id"/>/<s:property value="company.logoPath"/>"  style="width:40px;height:40px;margin-top:4px;cursor:default;"/>
				             </s:else>
	 		            </s:else>
		             <input type="hidden" id="cpyLogth" name="company.logoPath" value="<s:property value="company.logoPath"/>"/>
		             <input type="hidden" id="isTimeUp" name="isTimeUp" value=""/>
		             <input type="hidden" id="timeFileName" name="timeFileName" value=""/>
		          </td>
 		          <td></td>
 		       </tr>
		       <tr>
		         <td>公司名称：</td>
		         <td><input type="text" id="companyName" name="company.name" value="<s:property value="company.name"/>" width="150px"/></td>
		       </tr>
		       <tr>
		         <td>公司前缀：</td>
		         <td><input type="text" id="companyPrefix" name="company.prefix" value="<s:property value="company.prefix"/>" width="150px"/></td>
		       </tr>
		       <!-- 
		       <tr>
		         <td colspan="2" align="center" style="text-align: center;" id="inputTools">
		           <s:if test="company==null || #cts_emplcpyid == #cts_companyid">
			            <input type="button" id="enterSave" name="enterSave" value="确认" onclick="saveCompany()"/>
			            <input type="reset" id="reset" name="reset" value="重置"/>
		           </s:if>
		           <s:else>&nbsp;</s:else>
		         </td>
		       </tr>
		        -->
		       <tr style="display:none;" id="showCompanyInfo">
		          <td colspan="2" ><span style="color:red">公司已禁用</span></td>
		       </tr>
		     </table>
	    </form>
  </body>
</html>
